package com.example.demo.springboot.mqclient.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * TopicConsumer:Topic模式[动态路由膜式]
 *
 * @author zhangxiaoxiang
 * @date 2020/11/16
 */
@Component
@Slf4j
public class TopicConsumer {
    /**
     * crm监听话单回调
     *
     * @param msg 回调信息[主要是话单ID(当然可以拓展属性,比如话单状态等等)]
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    // 绑定交换机[指定交换机模式和对应名称name和value都行,一样的]
                    exchange = @Exchange(type = ExchangeTypes.TOPIC, name = MqConsumerConstant.TOPIC_CALLLOG_EXCHANGE),
                    // 绑定队内[不绑定会直接创建临时队内,一般业务都会指定队列名称]
                    value = @Queue(name = MqConsumerConstant.CRM_CALLLOG_QUEUE),
                    // 绑定的键(或模式)。多个元素将导致多个绑定[crm系统和erp都消费]
                    key = {"callback.crm.*","callback.erp.*"}
            )
    })
    public void crmListener(String msg) {
        log.info("crm系统收到外呼话单回调[执行业务逻辑]:{}", msg);
    }

    /**
     * zhiyu监听话单回调
     *
     * @param msg 回调信息[主要是话单ID(当然可以拓展属性,比如话单状态等等)]
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    exchange = @Exchange(type = ExchangeTypes.TOPIC, name = MqConsumerConstant.TOPIC_CALLLOG_EXCHANGE),
                    value = @Queue(name = MqConsumerConstant.ZHIYU_CALLLOG_QUEUE),
                    key = MqConsumerConstant.ZHIYU_CALLLOG_KEY
            )
    })
    public void zhiYuListener(String msg) {
        log.info("zhiYu系统收到外呼话单回调[执行业务逻辑]:{}", msg);
    }
}
